<?php  if ( ! defined('IN_DiliCMS')) exit('No direct script access allowed');
	class Frontget_ml extends CI_Model{
		
		function __construct()
		{
			parent::__construct();	
		}
		
		function get_site_settings()
		{
			$sql="select * from  dili_site_settings";
			$siteSettings=$this->db->query($sql)->row_array();
			return $siteSettings;
		}
		function get_lineclass()	//获取分类模型列表，用于导航显示
		{
			$sql="select classid,classname,parentid from  dili_u_c_trav_lines";
			$contentModels=$this->db->query($sql)->result();
			//$lines_title[$item->id]=$item->trav_title;
			$lineclass="";
			foreach($contentModels as $class){
				$lineclass['classname'][$class->classid]=$class->classname;
				$lineclass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
		//		$lineclass[$class->classid]['parentid']=$class->parentid;
				$lineclass['parentid'][$class->parentid][$class->classid]=$class->classname;//父类ID为索引
			}
		//	print_r($lineclass);
			return $lineclass;
		}
		// function getModelClass()	//获取大分类
		// {
			// $sql="select id,name,description from  dili_models";
			// $contentModels=$this->db->query($sql)->result();
			// $ModelClass="";
			// foreach($contentModels as $class){
				// $ModelClass['modelname'][$class->id]=$class->classname;
				// $ModelClass['description'][$class->id]=$class->description;		//子类ID为索引查找父类id
			// }
			// return $ModelClass;
		// }
		function getTicketClass()	//获取门票分类模型信息
		{
			$sql="select classid,classname,parentid from  dili_u_c_ticket";
			$contentModels=$this->db->query($sql)->result();
			$TicketClass="";
			foreach($contentModels as $class){
				$TicketClass['classname'][$class->classid]=$class->classname;
				$TicketClass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
				$TicketClass['parentid'][$class->parentid][$class->classid]=$class->classname;//父类ID为索引
			}
		//	print_r($lineclass);
			return $TicketClass;
		}
		function getCityClass()	//获取城市分类模型信息
		{
			$sql="select classid,city_name,parentid from  dili_u_c_city";
			$contentModels=$this->db->query($sql)->result();
			$CityClass="";
			foreach($contentModels as $class){
				$CityClass['city_name'][$class->classid]=$class->city_name;
				$CityClass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
				$CityClass['parentid'][$class->parentid][$class->classid]=$class->city_name;//父类ID为索引
			}
		//	print_r($lineclass);
			return $CityClass;
		}
		
		function get_strategy()
		{
			$sql="select classid,classname,parentid from  dili_u_c_class_strategy";
			$contentModels=$this->db->query($sql)->result();
			$tagsclass="";
			foreach($contentModels as $class){
				$tagsclass['classname'][$class->classid]=$class->classname;
				$tagsclass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
				$tagsclass['parentid'][$class->parentid][$class->classid]=$class->classname;//父类ID为索引
			}
			//print_r($lineclass);
			return $tagsclass;
		}
		function get_newsclass()	//获取新闻分类信息
		{
			$sql="select classid,classname,parentid from  dili_u_c_site_news";
			$contentModels=$this->db->query($sql)->result();
			$newsclass="";
			foreach($contentModels as $class){
				$newsclass['classname'][$class->classid]=$class->classname;
				$newsclass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
				$newsclass['parentid'][$class->parentid][$class->classid]=$class->classname;//父类ID为索引
			}
		//	print_r($lineclass);
			return $newsclass;
		}	
		function get_tagsclass()	//获取温泉常识分类信息
		{
			$sql="select classid,classname,parentid from  dili_u_c_class_tags";
			$contentModels=$this->db->query($sql)->result();
			$tagsclass="";
			foreach($contentModels as $class){
				$tagsclass['classname'][$class->classid]=$class->classname;
				$tagsclass['fpid'][$class->classid]=$class->parentid;		//子类ID为索引查找父类id
				$tagsclass['parentid'][$class->parentid][$class->classid]=$class->classname;//父类ID为索引
			}
			//print_r($lineclass);
			return $tagsclass;
		}		
	
		function get_indexpage_lines($lineclass=0)	//获取首页线路列表
		{
			$i=0;
		//	print_r($lineclass);
			foreach($lineclass['parentid'][1] as $key=>$value){	//筛选数组parentid为0的结果
				if($i>=4){break;}
		//		print_r($key);
		//		print_r($lineclass[$key]['parentid']);
 		//	 if($lineclass['parentid'][1][$key]==0):	
					$classid="'1-$key'";
					$sql="select  id,line_class,update_time,trav_title,price_per,departure_date,transparency,tuijian,name,folder,type from dili_u_m_trav_lines as l left join  dili_attachments as a on a.content=l.id where INSTR(line_class,$classid)  group by id  limit 8";
					
					$indexpage_lines[$key]=$this->db->query($sql)->result();
					$i++;
		//	  endif; 
			 }
			return $indexpage_lines;
		}
		function getIndexGuide($strategyclass=0)	//获取首页
		{
			$i=0;$j=0;$IndexGuide="";
			foreach($strategyclass['parentid'] as $key1=>$value1){	//筛选数组parentid为0的结果
				if($i>0){break;}
				foreach($strategyclass['parentid'][$key1] as $key=>$value){	//筛选数组parentid为0的结果
					if($j>2){break;}
					if($strategyclass['parentid'][$key1][$key]==0):
					//$classid=",".$key.",";
					$sql="select s.*,name,folder,type from dili_u_m_strategy as s left join  dili_attachments as a on a.content=s.id where strategy_type=',".$key.",'  group by id  limit 4";
					$IndexGuide[$j][$key]=$this->db->query($sql)->result();
					$IndexGuide["id"][$j]=$key;
					$j++;
					endif;
				}
				$i++;
			}
		//	print_r($IndexGuide);
			return $IndexGuide;
		}		
		function get_commend_lines($cateid=0)	//获取推荐线路列表
		{
			$datawhere=" and model=1 ";
			if($cateid){$datawhere.= "and INSTR(line_class,',$cateid-')";}		
			$sql="select  id,trav_title,price_per,departure_date,line_info,name,folder,type  from dili_u_m_trav_lines as l inner join dili_attachments as a on a.content=l.id where tuijian=1 $datawhere  group by content limit 5";
		//	print_r($sql);
			$commend_lines=$this->db->query($sql)->result();
			return $commend_lines;
		}
		function getHotLineList($cateid=0)		//获取热门线路列表
		{
			$datawhere=" and model=1 ";
			if($cateid){$datawhere.= "and INSTR(line_class,',$cateid-')";}		
			$sql="select  id,trav_title,price_per,departure_date,line_info,name,folder,type  from dili_u_m_trav_lines as l inner join dili_attachments as a on a.content=l.id where hotlines=1 $datawhere  group by content limit 5";
		//	print_r($sql);
			$commend_lines=$this->db->query($sql)->result();
			return $commend_lines;
		}
		function getLastLineList($cateid=0)		//获取最新线路列表
		{
			$datawhere=" and model=1 ";
			if($cateid){$datawhere.= "and INSTR(line_class,',$cateid-')";}		
			$sql="select  id,trav_title,price_per,departure_date,line_info,name,folder,type  from dili_u_m_trav_lines as l inner join dili_attachments as a on a.content=l.id where 1=1 $datawhere  group by content order by id desc limit 5";
		//	print_r($sql);
			$commend_lines=$this->db->query($sql)->result();
			return $commend_lines;
		}
		function get_slider_lines($cateid=0)	//获取首页幻灯片线路,及图片
		{
			$datawhere=" and model=1 ";
			if($cateid){$datawhere.=" and (INSTR(line_class,'-$cateid,') or INSTR(line_class,',$cateid-'))";}
			$sql="select  content,name,folder,type  from dili_u_m_trav_lines as l inner join dili_attachments as a on a.content=l.id where transparency=1 $datawhere  group by content limit 5";
			$slider_lines=$this->db->query($sql)->result();
			return $slider_lines;	
		}
		function get_line_annex($cateid=0)	//获取线路图片附件
		{
			$datawhere=" model=1 ";
			if($cateid){
				$datawhere.="and (INSTR(line_class,'-$cateid,') or INSTR(line_class,',$cateid-'))";
			}
			$sql="select  content,name,folder,type  from dili_u_m_trav_lines as l inner join dili_attachments as a on a.content=l.id where  $datawhere  group by content limit 5";
			//	print_r($sql);
			$slider_lines=$this->db->query($sql)->result();
			return $slider_lines;
		}		
		function get_right_lines()	//获取右侧线路列表
		{
			
		//	$right_lines[13]=$this->get_Visa_agent(13);//获取右侧签证代办列表
			$right_lines[4]=$this->get_Visa_agent(4);//获取右侧签证代办列表
		//	print_r($right_lines);
			return $right_lines;
		}	
		function get_Visa_agent($classid=0)	//获取右侧签证代办列表
		{
			$sql="select id,trav_title,price_per,departure_date   from dili_u_m_trav_lines  where  INSTR(line_class,'$classid-')  limit 10";		
			$Visa_agent=$this->db->query($sql)->result();
			return $Visa_agent;			
		}
		function get_lineInfo($lineId=0)	//获取文章内容
		{
			if ($lineId){
				$sql="select id,trav_title,line_info,line_class,price_per,departure_date,Departure_city,TravelTime,trav_feature,service_include,own_cost,destination from  dili_u_m_trav_lines  where id=".$lineId."  limit 1 ";
				$lineInfo['list']=$this->db->query($sql)->result();
				
				$sql_annex="select name,folder,realname,type,image from   dili_attachments  where content=".$lineId." and model=1 order by image desc limit 5 ";
			//	exit($sql);
				$lineInfo['annex'][$lineId]=$this->db->query($sql_annex)->result();
	
				return $lineInfo;
			}else{
				return false;
			}
		}	
		function get_announcement()	//获取网站公告
		{
			$sql="select content from  dili_u_m_announcement where viewflag limit 3";
			$announcement=$this->db->query($sql)->result();
			return $announcement;
		}
		function get_art_num($cateid=0)	//获取某类下的记录数
		{
			if ((int)$cateid){
				$sql="select count(id) as icount from  dili_u_m_trav_lines  where  INSTR(line_class,',$cateid-') or  INSTR(line_class,'-$cateid,')";
				$art_num=$this->db->query($sql)->row_array();
		//		print_r($art_num);
				return $art_num["icount"];
			}else{
				return 0;
			}
		}	
		function get_friend_links(){
			$sql="select link_name,link_address from dili_u_m_friend_links where is_viewflag=1 limit 4";
			$friend_links=$this->db->query($sql)->result();
			return $friend_links;
		}	
		function getLineSearch($StartDate,$EndDate,$txtKeyName,$type=0,$begin_record=0,$per_page=0)	//按条件查询温泉线路
		{
			$datawhere="";
			if($txtKeyName){
				$datawhere.=" and trav_title like '%$txtKeyName%' ";
			}
			if($type==0){	//统计总数
				$sql="select count(id) as icount from  dili_u_m_trav_lines where 1=1 $datawhere";
				$totalRows=$this->db->query($sql)->result();
				$totalRows=$totalRows[0]->icount;
				return $totalRows;
			}else{
				$sql="select * from  dili_u_m_trav_lines where 1=1 $datawhere order by id desc limit $begin_record,$per_page";
				$LineSearch['list']=$this->db->query($sql)->result();
					
				$sql_annex="select id,model,name,folder,type from  dili_u_m_trav_lines as l inner join dili_attachments as a on l.id=a.content where 1=1 $datawhere   group by id order by id desc limit $begin_record,$per_page";
				$annex=$this->db->query($sql_annex)->result();
				foreach($annex as $item){
				$LineSearch['annex'][$item->id]=$item;
				}
				return $LineSearch;
				}
				}			
	}